package oop.controller.action.test;

import java.util.List;

import oop.controller.action.DefaultAction;
import oop.data.Test;

public abstract class AbstractEditAction extends DefaultAction {

	protected Test test;

	@Override
	public void perform() throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		List<Test> tests = Test.fetchById(id);
		if (tests.isEmpty()) {
			request.setAttribute("message", "Không tìm thấy đề thi: " + id);
			setNextAction("error");
			return;
		}
		
		test = tests.get(0);
		performDetail();
		request.setAttribute("test", test);
	}

	protected abstract void performDetail() throws Exception;
	
}
